﻿//AJAX请求配置
var Servlet = {
    UserLogin: 'servlet/loginResult.asp',
    GetUserBaseInfo: 'json.action?method=getUserBaseInfo',
    GetUserExtInfo: 'json.action?method=userExtInfo',
    GetNewMessages: 'servlet/UserNewMessages.asp',
    GetMyCardInfo: 'json.action?method=getMyCardInfo',
    LossMyCard: 'servlet/LossUserCard.asp',
    GetPaidCards: 'json.action?method=getPaidCards',
    GetPayForNItems: 'json.action?method=getPayForNItems',
    GetPayForEItems: 'json.action?method=getPayForEItems',
    GetBillHistoryList:'json.action?method=getBillHistoryList',
    GetRecBanks: 'json.action?method=getRecBanks',
    GetMyBanks: 'json.action?method=userBanks',
    GetOtherBanks: 'json.action?method=otherBanks',
    GetAllBanks: 'json.action?method=allBanks',
    GetSameNameUsers: 'servlet/SameNameUsers.asp',
    GetMySafeOptions: 'json.action?method=getMySafeOptions',
    setUserBank: 'json.action?method=setUserBanks',
    checkPayLimit: 'json.action?method=checkPayLimit'
};

var feeItems = new Array();

var funSetUserBank = function(bank) {
    var ajax = new AJAXFunction({ url: Servlet.setUserBank + '&bank=' + bank } );
    ajax.SendFun();
}

var GetCurrentUserBaseInfo = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetUserBaseInfo });
    ajax.SuFun = function (data) {
        var userInfo = data.Data;
        $('#img_UserIcon').attr('src', userInfo.UserIcon);
        $('#li_UserName').html(GetTimeAPMName() + '好，' + userInfo.UserName);
        $('#li_UserNo').html('学  号：' + userInfo.UserNo);
        $('#li_LastLoginTime').html('上次登录时间：' + userInfo.LastLoginTime);

        //设置头像浮动层
        CreateSetIconBox(userInfo);
    };
    ajax.SendFun();
};

var CreateSetIconBox = function (userInfo) {
    var setIconBox = $('<div>').attr('id', 'userHead');

    var titleBox = $('<div>').addClass('headInfo').append(
        '修改我的头像',
        $('<span>').click(function () { setIconBox.hide(); })
    ).appendTo(setIconBox);

    var infoBox = $('<div>').addClass('headBox').append(
        $('<p>').addClass('leftBox').append(
            $('<span>').addClass('span01').html('新的头像'),
            $('<span>').addClass('span03').append(
                $('<input>').attr({ 'name': 'btn_SelectFile', 'id': 'btn_SelectFile', 'value': '点击选择图片', 'type': 'button' })
           ),
           $('<span>').addClass('span02').html('图片文件最大5MB，支持 .jpg .bmp 的图片格式。')
        ),
        $('<p>').addClass('rightBox').append(
           $('<span>').addClass('span01').html('当前头像'),
           $('<img>').attr({ 'src': userInfo.UserIcon, 'alt': '' }),
           $('<span>').addClass('span01').html('上次头像'),
           $('<img>').attr({ 'src': userInfo.LastIcon, 'alt': '' }),
           $('<span>').addClass('span04').html('<a href="javascript:void(0);">使用</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:void(0);">删除</a>')
        )
    ).appendTo(setIconBox);

    var btnBox = $('<div>').addClass('btnBox').append(
         $('<input>').attr({ 'name': 'btn_SubmitHeadIcon', 'id': 'btn_SubmitHeadIcon', 'value': '确定', 'type': 'button' }).click(function () { setIconBox.hide(); })
    ).appendTo(setIconBox);

    setIconBox.appendTo($('#userBlock'));
    $('div.headIconBox > p').click(function () {
        /*if ($('#msgBox').length > 0 && $('#msgBox').css('display') != 'none') {
            $('#msgBox').slideUp(200, function () { setIconBox.show(); });
        }
        else {
            setIconBox.show();
        }*/
    });
};

var GetCurrentUserExtInfo = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetUserExtInfo });
    ajax.SuFun = function (data) {
        var userInfo = data.Data;
        $('#lb_MyBankCount').html(userInfo.BankCount + '家');

        var level = userInfo.SafeLevel;
        if (1 == level) {
            $('#lb_MySafeLevel').attr('class', 'red').html('低&nbsp;&nbsp;');
        }
        if (2 == level) {
            $('#lb_MySafeLevel').attr('class', 'blue').html('中&nbsp;&nbsp;');
        }
        if (3 == level) {
            $('#lb_MySafeLevel').attr('class', 'green').html('高&nbsp;&nbsp;');
        }
    };
    ajax.SendFun();
};

var GetNewMessages = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetNewMessages });
    ajax.SuFun = function (data) {
        var msgData = data.Data;
        if (msgData.length > 0) {
            $('<span>').attr('id', 'mcBox').html(msgData.length).click(function () {
                msgBox.slideDown(200);
            }).appendTo($('#userBlock'));

            var msgBox = $('<div>').attr('id', 'msgBox');
            var msgUl = $('<ul>').appendTo(msgBox);
            $('<li>').addClass('tc').html('消息').appendTo(msgUl);
            for (var i = 0; i < msgData.length; i++) {
                var msg = msgData[i];
                if (msg.Type == 1) {
                    //var hrefAccept = $('<a href="bang.html?payval=' + msg.Money + '&payforName=' + msg.SenderName + '&payforId=' + msg.SenderNo + '&payformsgId=' + msg.MessageId + '" title="接受并处理该消息" target="_blank">接受</a>');
                    var hrefAccept = $('<a href="javascript:void(0);" title="接受并处理该消息">接受</a>');
                    PayforItemClick.call(hrefAccept, { 'ItemName': '帮' + msg.SenderName + '充值一卡通', 'ItemPrice': parseFloat(msg.Money) }, 2);

                    $('<li>').append(
                        $('<label>').addClass('senderName').html(msg.SenderName),
                        $('<label>').addClass('senderId').html('(' + msg.SenderNo + ')'),
                        $('<label>').addClass('info').html(' 请你帮他充值一卡通 '),
                        $('<label>').addClass('money').html(' ' + msg.Money + ' '),
                        $('<label>').addClass('info').html(' 元 '),
                        $('<label>').addClass('content').html(' 留言：' + msg.Content),
                        $('<span>').append(
                            hrefAccept,
                            ' / ',
                            $('<a>').attr({ 'href': 'javascript:void(0);', 'title': '忽略该消息' })
                            .click(function () {
                                $(this).parent().parent().remove();
                            })
                            .html('忽略')
                        ),
                        $('<span>').addClass('time').html(msg.SendTime)
                    ).appendTo(msgUl);
                } else {
                    $('<li>').append(
                        $('<label>').addClass('senderName').html(msg.SenderName),
                        $('<label>').addClass('info').html(' 已为你充值一卡通 '),
                        $('<label>').addClass('money').html(' ' + msg.Money + ' '),
                        $('<label>').addClass('info').html(' 元 '),
                        $('<label>').addClass('content').html(' 留言：' + msg.Content),
                        $('<span>'),
                        $('<span>').addClass('time').html(msg.SendTime)
                    ).appendTo(msgUl);
                }
            }
            $('<li>').addClass('tc').append(
                $('<input>').attr({ 'type': 'button', 'value': '', 'title': '收起消息' }).click(function () {
                    msgBox.slideUp(200);
                })
            ).appendTo(msgUl);
            msgBox.append(msgUl).appendTo($('#userBlock'));
        }
    };
    ajax.SendFun();
};

var GetMyCardInfo = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetMyCardInfo });
    ajax.SuFun = function (data) {
        var cardInfo = data.Data;
        $('#lb_CardMoney').html(cardInfo.LastMoney);
        $('#lb_CardStatus').attr({ 'class': cardInfo.Status == 1 ? 'normalInfo' : 'normalRedInfo' }).html(cardInfo.Status == 1 ? '正常' : '该帐户暂时不能网上充值');
        $('#lb_CardNo').html(cardInfo.CardNo);
		if (cardInfo.Status != 1) {
			$('#btn_SubmitPay').attr("disabled", true);
		}
    };
    ajax.SendFun();
};

var LossMyCard = function () {
    var cardPass;
    if ($('#cardPassword'))
        cardPass = $('#cardPassword').val();

    if (!cardPass || cardPass == '') {
        Alert('请输入一卡通的密码！');
        return;
    }

    var ajax = new AJAXFunction({ url: Servlet.LossMyCard, param: { cardPassword: cardPass} });
    ajax.SuFun = function (data) {
        var result = data.Data;
        if (result) {
            Alert('目前暂不支持一卡通挂失功能！');
            //Alert('一卡通挂失成功！');
            //$('#div_LossCard, label.status').hide();
            //ShowLossBox = false;
            //$('#lb_CardStatus').attr({ 'class': 'normalRedInfo' }).html('已挂失');
        }
    };
    ajax.SendFun();
};

var GetPaidCards = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetPaidCards });
    ajax.SuFun = function (data) {
        var cardsData = data.Data;
        for (var i = 0; i < cardsData.length; i++) {
            var card = cardsData[i];
            var element = $('<a>').attr('href', 'javascript:void(0);').html(card.FaceValue + '元');
            PaidCardClick.call(element, card, i);
            $('#btn_SubmitPay').before(element);
        }
        $('#txt_PayValue').val(0)
    };
    ajax.SendFun();
};

var PaidCardClick = function (data, idx) {
    this.bind({
        'click': function () {
            if (!$(this).hasClass('actived')) {
                $('li.payCardBox > .actived').removeClass('actived');
                $(this).addClass('actived');
                $('#sp_PaidInfoArr').attr('class', 'sp' + (idx + 1)).show();

                var _cardVal = data.RealValue;
                var _otherVal = _cardVal * data.Charge / 100;
				if (_otherVal < 0.1) {
					_otherVal = 0.1;
				}
                var _allval = _cardVal + _otherVal;
                $('#txt_PayValue').val(data.FaceValue);
                $('#p_PaidInfo').attr('class', 'info').html('支付总金额 ' + _allval.toFixed(2) + ' = ' + data.RealValue + '元+' + _otherVal.toFixed(2) + '元手续费');
            }
        }
    });
};

var GetPayForItems = function () {
    //先请求必交项目 
    var ajax = new AJAXFunction({ url: Servlet.GetPayForNItems });
    ajax.SuFun = function (data) {
        var itemsData = data.Data;
        var itemCount = 0;
        var divBox = $('<div>').addClass('payforItemBox').append('<div class="empty"></div>');

        for (var i = 0; i < itemsData.length; i++) {
            if (i > 0) {
                $('<div class="empty"></div>').appendTo(divBox);
            }

            var category = itemsData[i];
            $('<div>').addClass('category')
            .append(
                $('<img src="' + category.CategoryIcon + '" alt="' + category.CategoryName + '" />'),
                $('<label>' + category.CategoryName + '</label>'),
                $('<span>').attr({ 'class': i == 0 ? 'down' : 'right' }).click(function () {
                    var _this = $(this);
                    var _box = _this.parent().next();
                    if (_this.hasClass('down')) {
                        _this.removeClass('down').addClass('right');
                        _box.hide();
                    } else {
                        _this.removeClass('right').addClass('down');
                        _box.show();
                    }
                })
            )
            .appendTo(divBox);

            var categoryItmes = category.Items;
            itemCount += categoryItmes.length;
            var itemBox = $('<div>').addClass('itemBox');
            if (i > 0) {
                itemBox.css('display', 'none');
            }
            var itemUl = $('<ul>');

            for (var n = 0; n < categoryItmes.length; n++) {
                var itemLi = $('<li>')
                .append(
                    $('<span class="name"><label>' + categoryItmes[n].ItemName + '</label></span>'),
                    $('<span class="time">' + categoryItmes[n].ItemTime + '</span>'),
                    $('<span class="price">' + categoryItmes[n].ItemPrice.toFixed(2) + '</span>'),
                    $('<span class="info">元</span>')
                //$('<span class="add"></span>')
                )
                .appendTo(itemUl);

                var sp = $('<span class="add"></span>');
                PayforItemClick.call(sp, categoryItmes[n], 1);
                sp.appendTo(itemLi);
            }

            itemUl.appendTo(itemBox);
            itemBox.appendTo(divBox);
        }

        $('#div_NItemTitle').after(divBox);
        $('#lb_NItemCount').html(' ' + itemCount + ' ');

        //请求选交项
        GetPayForEItems();
    };
    ajax.SendFun();
};

var GetPayForEItems = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetPayForEItems });
    ajax.SuFun = function (data) {
        var itemsData = data.Data;
        var itemCount = 0;
        var divBox = $('<div>').addClass('payforItemBox').append('<div class="empty"></div>');

        for (var i = 0; i < itemsData.length; i++) {
            if (i > 0) {
                $('<div class="empty"></div>').appendTo(divBox);
            }
            
            var category = itemsData[i];
            $('<div>').addClass('category')
            .append(
                $('<img src="' + category.CategoryIcon + '" alt="' + category.CategoryName + '" />'),
                $('<label>' + category.CategoryName + '</label>'),
                $('<span>').attr({ 'class': i == 0 ? 'down' : 'right' }).click(function () {
                    var _this = $(this);
                    var _box = _this.parent().next();
                    if (_this.hasClass('down')) {
                        _this.removeClass('down').addClass('right');
                        _box.hide();
                    } else {
                        _this.removeClass('right').addClass('down');
                        _box.show();
                    }
                })
            )
            .appendTo(divBox);

            var categoryItmes = category.Items;
            itemCount += categoryItmes.length;
            var itemBox = $('<div>').addClass('itemBox');
            if (i > 0) {
                itemBox.css('display', 'none');
            }
            var itemUl = $('<ul>');

            for (var n = 0; n < categoryItmes.length; n++) {
                var itemLi = $('<li>')
                .append(
                    $('<span class="name"><label>' + categoryItmes[n].ItemName + '</label></span>'),
                    $('<span class="time">' + categoryItmes[n].ItemTime + '</span>'),
                    $('<span class="price">' + categoryItmes[n].ItemPrice.toFixed(2) + '</span>'),
                    $('<span class="info">元</span>')
                    //$('<span class="add"></span>')
                )
                .appendTo(itemUl);

                var sp = $('<span class="add"></span>');
                PayforItemClick.call(sp, categoryItmes[n], 1);
                sp.appendTo(itemLi);
            }

            itemUl.appendTo(itemBox);
            itemBox.appendTo(divBox);
        }

        $('#div_EItemTitle').after(divBox);
        $('#lb_EItemCount').html(' ' + itemCount + ' ');
    };
    ajax.SendFun();
};

var PayforItemClick = function (itemData, orgElementType) {

    if (1 == orgElementType) {
        this.click(function () {
            if (feeItems.length >= 1) {
	            Alert('一次只能选择一个项目！');
		        return;
	        }
            if ($(this).hasClass('add')) {
                $(this).removeClass('add').addClass('notadd');
                AddItemToCart(itemData, $(this), orgElementType);
            }
        });
    }

    if (2 == orgElementType) {
        this.click(function () {
            if (feeItems.length >= 1) {
	            Alert('一次只能选择一个项目！');
		        return;
	        }
            $(this).parent().parent().hide();
            AddItemToCart(itemData, $(this), orgElementType);
        });
    }
};

var AddItemToCart = function (itemData, orgElement, orgElementType) {
    if (feeItems.length >= 1) {
	    Alert('一次只能选择一个项目！');
		return;
	}
	
    var li = $('<li>')
    .append(
        $('<span class="name"><label>' + itemData.ItemName + '</label></span>'),
        $('<span class="info">￥</span>'),
        $('<span class="price">' + itemData.ItemPrice.toFixed(2) + '</span>'),
        $('<span class="info">元</span>')
    )
    .appendTo($('#ul_cartItemBox'));
	
	feeItems.push(itemData.ItemId + ':' + itemData.ItemPrice);

    var sp = $('<span class="sub"></span>');
    CartItemClick.call(sp, orgElement, itemData, orgElementType);
    sp.appendTo(li);

    var hasCount = parseInt($('#sp_CartItemCount').html(), 10);
    $('#sp_CartItemCount').html(hasCount + 1);

    var hasMoney = parseFloat($('#sp_CartItemMoney').html());
	hasMoney = hasMoney + itemData.ItemPrice;
	var amtMoney = hasMoney * 0.002;
	if (amtMoney < 0.1) amtMoney = 0.1;
    $('#sp_CartItemMoney').html(hasMoney.toFixed(2));
	$('#sp_CartItemMoney2').html(amtMoney.toFixed(2));
	$('#sp_CartItemMoney3').html((hasMoney + amtMoney).toFixed(2));
};

var CartItemClick = function (itemCtlSp, itemData, orgElementType) {
    if (0 == orgElementType) {
        this.click(function () {
            RemoveFromCart($(this), itemData);
        });
    }

    if (1 == orgElementType) {
        this.click(function () {
            itemCtlSp.removeClass('notadd').addClass('add');
            RemoveFromCart($(this), itemData);
        });
    }

    if (2 == orgElementType) {
        this.click(function () {
            if (itemCtlSp)
                itemCtlSp.parent().parent().show();
            RemoveFromCart($(this), itemData);
        });
    }
};

var RemoveFromCart = function (itemElement, itemData) {
    var hasCount = parseInt($('#sp_CartItemCount').html(), 10);
    $('#sp_CartItemCount').html(hasCount - 1);

    var hasMoney = parseFloat($('#sp_CartItemMoney').html());
	hasMoney = hasMoney - itemData.ItemPrice;
	var amtMoney = hasMoney * 0.002;
	if (amtMoney < 0.1) amtMoney = 0.1;
    $('#sp_CartItemMoney').html(hasMoney.toFixed(2));
	$('#sp_CartItemMoney2').html(amtMoney.toFixed(2));
	$('#sp_CartItemMoney3').html((hasMoney + amtMoney).toFixed(2));

    var feeItem = itemData.ItemId + ':' + itemData.ItemPrice;
    feeItems.splice($.inArray(feeItem, feeItems), 1);
	
    itemElement.parent().remove();
};

var GetBillHistoryList = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetBillHistoryList });
    ajax.SuFun = function (data) {
        var itemsData = data.Data;
        for (var i = 0; i < itemsData.length; i++) {
            var UL = $('<ul>');
            if (i > 0) {
                UL.css('display', 'none');
            }

            var subData = itemsData[i].Items;
            for (var n = 0; n < subData.length; n++) {
                $('<li>')
                .append(
                    $('<span class="title">' + subData[n].Title + '</span>'),
                    $('<span class="price">￥' + subData[n].Money.toFixed(2) + '元</span>'),
                    $('<span class="time">' + subData[n].Time + '</span>'),
                    $('<span>　　' + subData[n].Status + '</span>'),
                   // $('<span>').attr({ 'class': subData[n].Status == 0 ? 'sred' : 'sgreen' }),
                    $('<span class="sub"></span>').click(function () {
                        $(this).parent().remove();
                    })
                )
                .appendTo(UL);
            }
            UL.appendTo($('#div_billListBox'));
        }
    }
    ajax.SendFun();
};

var GetBanks = function () {
    //先获取推荐银行
    var ajax = new AJAXFunction({ url: Servlet.GetRecBanks });
    ajax.SuFun = function (data) {
        var bankData = data.Data;
        var radio = $('<input type="radio" name="radio_Bank" id="radio_Bank_' + bankData.BankId + '" value="' + bankData.BankId + '" />');
        BankRadioClick.call(radio, bankData);

        var label = $('<label for="radio_Bank_' + bankData.BankId + '"></label>').css('background', 'url("' + bankData.BankIcon + '") no-repeat left top');
        var div = $('<div>')
        .addClass('recBankbox')
        .append(
            radio,
            label,
            $('<span id="sp_BankSaveUnit">元</span>').css('display', 'none'),
            $('<span id="sp_BankSaveMoney" class="money">0</span>').css('display', 'none'),
            $('<span id="sp_BankSaveTxt">可为你节省</span>').css('display', 'none')
        );

        var adImg = $('<img>').attr({ 'src': bankData.BankAdImage, 'alt': '' });
        $('#div_RecBankTitle').after(adImg).after(div);

        //获取我的银行
        GetMyBanks();
    };
    ajax.SendFun();
};

var GetMyBanks = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetMyBanks });
    ajax.SuFun = function (data) {
        var bankData = data.Data;
        for (var i = 0; i < bankData.length; i++) {
            var radio = $('<input type="radio" name="radio_Bank" id="radio_Bank_' + bankData[i].BankId + '" value="' + bankData[i].BankId + '" />');
            BankRadioClick.call(radio, bankData[i]);

            var label = $('<label for="radio_Bank_' + bankData[i].BankId + '"></label>').css('background', 'url("' + bankData[i].BankIcon + '") no-repeat left top');

            radio.appendTo($('#div_MyBankBox'));
            label.appendTo($('#div_MyBankBox'));
        }

        //获取其他银行
        GetOtherBanks();
    };
    ajax.SendFun();
};

var GetOtherBanks = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetOtherBanks });
    ajax.SuFun = function (data) {
        var bankData = data.Data;
		$('<option value="">选择其他银行</option>').appendTo($('#sel_OtherBank'));
        for (var i = 0; i < bankData.length; i++) {
            $('<option value="' + bankData[i].BankId + '">' + bankData[i].BankName + '</option>').appendTo($('#sel_OtherBank'));
        }

        $('#sel_OtherBank').change(function () {
            $('#sp_BankSaveMoney').html(0).hide();
            $('#sp_BankSaveUnit, #sp_BankSaveTxt').hide();
            $('input:[type=radio][name=radio_Bank]:checked').attr('checked', false);
        });
    };
    ajax.SendFun();
};

var GetBanks2 = function () {
    //先获取推荐银行
    var ajax = new AJAXFunction({ url: Servlet.GetRecBanks });
    ajax.SuFun = function (data) {
        var bankData = data.Data;
        var radio = $('<input type="radio" name="radio_Bank" id="radio_Bank_' + bankData.BankId + '" value="' + bankData.BankId + '" />');
        BankRadioClick.call(radio, bankData);

        var label = $('<label for="radio_Bank_' + bankData.BankId + '"></label>').css('background', 'url("' + bankData.BankIcon + '") no-repeat left top');
        var p = $('<p>')
        .addClass('right')
        .append(
            radio,
            label,
            $('<span id="sp_BankSaveTxt">可为你节省</span>').css('display', 'none'),
            $('<span id="sp_BankSaveMoney" class="money">0</span>').css('display', 'none'),
            $('<span id="sp_BankSaveUnit">元</span>').css('display', 'none')
        );

        var div1 = $('<div>').addClass('bankBox').append(
            $('<p class="left">推荐银行：</p>'),
            p
        );

        var div2 = $('<div id="div_RecBankImageBox">').addClass('bankBox').append(
            $('<p class="left"></p>'),
            $('<p class="right"><img src="' + bankData.BankAdImage + '" alt="" /></p>')
        );

        $('#div_SameNameBox').after(div2).after(div1);

        //获取我的银行
        GetMyBanks2();
    };
    ajax.SendFun();
};

var GetMyBanks2 = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetMyBanks });
    ajax.SuFun = function (data) {
        var bankData = data.Data;

        var div = $('<div id="div_MyBankBox">').addClass('bankBox').append($('<p class="left">常用银行：</p>'));
        var p = $('<p>').addClass('right');

        for (var i = 0; i < bankData.length; i++) {
            var radio = $('<input type="radio" name="radio_Bank" id="radio_Bank_' + bankData[i].BankId + '" value="' + bankData[i].BankId + '" />');
            BankRadioClick.call(radio, bankData[i]);

            var label = $('<label for="radio_Bank_' + bankData[i].BankId + '"></label>').css('background', 'url("' + bankData[i].BankIcon + '") no-repeat left top');

            radio.appendTo(p);
            label.appendTo(p);
        }

        p.appendTo(div);
        $('#div_RecBankImageBox').after(div);
        //获取其他银行
        GetOtherBanks2();
    };
    ajax.SendFun();
};

var GetOtherBanks2 = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetOtherBanks });
    ajax.SuFun = function (data) {
        var bankData = data.Data;

        var div = $('<div>').addClass('bankBox').append($('<p class="left">其他银行：</p>'));
        var p = $('<p>').addClass('right');
        var select = $('<select>').attr('id', 'sel_OtherBank');

        $('<option value="">选择其他银行</option>').appendTo(select);
        for (var i = 0; i < bankData.length; i++) {
            $('<option value="' + bankData[i].BankId + '">' + bankData[i].BankName + '</option>').appendTo(select);
        }

        select.change(function () {
            $('#sp_BankSaveMoney').html(0).hide();
            $('#sp_BankSaveUnit, #sp_BankSaveTxt').hide();
            $('input:[type=radio][name=radio_Bank]:checked').attr('checked', false);
        }).appendTo(p);

        p.appendTo(div);
        $('#div_MyBankBox').after(div);
    };
    ajax.SendFun();
};

var BankRadioClick = function (bankData) {
    this.click(function () {
        var save = bankData.BankSave;
        if (0 != save) {
            $('#sp_BankSaveMoney').html(bankData.BankSave).show();
            $('#sp_BankSaveUnit, #sp_BankSaveTxt').show();
        } else {
            $('#sp_BankSaveMoney').html(0).hide();
            $('#sp_BankSaveUnit, #sp_BankSaveTxt').hide();
        }

        $('#sel_OtherBank').val(0);
    });
};

var GetMyBanks3 = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetMyBanks });
    ajax.SuFun = function (data) {
        var bankData = data.Data;

        if (bankData.length > 0) {
            $('#sp_RemoveMyBank').show();
        }
        if (bankData.length < 4) {
            $('#sp_AddMyBank').show();
        };

        for (var i = 0; i < bankData.length; i++) {
            var radio = $('<input type="checkbox" name="chk_MyBank" id="chk_MyBank_' + bankData[i].BankId + '" value="' + bankData[i].BankId + '" />');
            BankRadioClick.call(radio, bankData[i]);
            var label = $('<label for="chk_MyBank_' + bankData[i].BankId + '"></label>').css('background', 'url("' + bankData[i].BankIcon + '") no-repeat left top');
            radio.appendTo($('#div_MyBankBox'));
            label.appendTo($('#div_MyBankBox'));
        }
    };
    ajax.SendFun();
};

var GetAllBanks = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetAllBanks });
    ajax.SuFun = function (data) {
        var bankData = data.Data;
        for (var i = 0; i < bankData.length; i++) {
            var radio = $('<input type="checkbox" name="chk_Bank" id="chk_Bank_' + bankData[i].BankId + '" value="' + bankData[i].BankId + '" />');
            BankRadioClick.call(radio, bankData[i]);
            var label = $('<label for="chk_Bank_' + bankData[i].BankId + '"></label>').css('background', 'url("' + bankData[i].BankIcon + '") no-repeat left top');
            radio.appendTo($('#div_AllBankListBox'));
            label.appendTo($('#div_AllBankListBox'));
        }

        $('<label>').addClass('other').html('展开所有银行').appendTo($('#div_AllBankListBox'));
    };
    ajax.SendFun();
};

var GetSameNameUserList = function (userName) {
    var ajax = new AJAXFunction({ url: Servlet.GetSameNameUsers, param: { NameKey: userName} });
    ajax.SuFun = function (data) {
        var userData = data.Data;
        for (var i = 0; i < userData.length; i++) {
            $('<li>')
            .append(
                $('<input type="radio" name="radio_SameUser" id="radio_SameUser_' + i + '" value="' + userData[i].UserId + '" />'),
                $('<label class="uName" for="radio_SameUser_' + i + '">' + userData[i].UserName + '</label>'),
                $('<label class="grade">' + userData[i].Grade + '</label>'),
                $('<label class="no">学号：' + userData[i].UserNo + '</label>')
            )
            .appendTo($('#ul_SameNameBox'));
        }
    };
    ajax.SendFun();
};

var GetUserSafeOptions = function () {
    var ajax = new AJAXFunction({ url: Servlet.GetMySafeOptions });
    ajax.SuFun = function (data) {
        var options = data.Data;
        if (options.Mobile == '') {
            $('#txt_Mobile').next().hide();
        } else {
            //            $('#txt_Mobile').hide();
            //            $('#txt_Mobile').next().html(options.Mobile);
            //            $('#sp_safeMobileInfo').html('&nbsp;');
            //            $('#btn_SubmitMobile').attr({ 'value': '修改', 'title': '修改验证手机号码' });
            ChangeMobile(options.Mobile, $('#sp_safeMobileInfo').html());
        }

        if (options.Email == '') {
            $('#txt_EMail').next().hide();
        } else {
//            $('#txt_EMail').hide();
//            $('#txt_EMail').next().html(options.Email);
//            $('#sp_safeEmailInfo').html('&nbsp;');
            //            $('#btn_SubmitEMail').attr({ 'value': '修改', 'title': '修改验证电子邮件' });
            ChangeEmail(options.Email, $('#sp_safeEmailInfo').html());
        }
    };
    ajax.SendFun();
};
